package com.turnengine.client.local.turn.command;

import org.apache.commons.lang.builder.CompareToBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * The Execute Turns.
 */
public class ExecuteTurns implements IExecuteTurns {

	/** The command id. */
	public static final short COMMAND_ID = 1802;

	/** The login id. */
	private long loginId;
	/** The instance id. */
	private int instanceId;
	/** The turns. */
	private int turns;

	/**
	 * Creates a new Execute Turns.
	 */
	public ExecuteTurns() {
	}

	/**
	 * Creates a new Execute Turns.
	 * @param loginId the login id
	 * @param instanceId the instance id
	 * @param turns the turns
	 */
	public ExecuteTurns(long loginId, int instanceId, int turns) {
		setLoginId(loginId);
		setInstanceId(instanceId);
		setTurns(turns);
	}

	/**
	 * Creates a new Execute Turns.
	 * @param iExecuteTurns the i execute turns
	 */
	public ExecuteTurns(IExecuteTurns iExecuteTurns) {
		setLoginId(iExecuteTurns.getLoginId());
		setInstanceId(iExecuteTurns.getInstanceId());
		setTurns(iExecuteTurns.getTurns());
	}

	/**
	 * Returns the login id.
	 * @return the login id.
	 */
	public long getLoginId() {
		return loginId;
	}

	/**
	 * Returns the instance id.
	 * @return the instance id.
	 */
	public int getInstanceId() {
		return instanceId;
	}

	/**
	 * Returns the turns.
	 * @return the turns.
	 */
	public int getTurns() {
		return turns;
	}

	/**
	 * Sets the login id.
	 * @param loginId the login id to set.
	 */
	public void setLoginId(long loginId) {
		this.loginId = loginId;
	}

	/**
	 * Sets the instance id.
	 * @param instanceId the instance id to set.
	 */
	public void setInstanceId(int instanceId) {
		this.instanceId = instanceId;
	}

	/**
	 * Sets the turns.
	 * @param turns the turns to set.
	 */
	public void setTurns(int turns) {
		this.turns = turns;
	}

	/**
	 * Returns the hash code.
	 * @return the hash code.
	 */
	@Override
	public int hashCode() {
		HashCodeBuilder hash = new HashCodeBuilder(1063, 37);
		hash.append(loginId);
		hash.append(instanceId);
		hash.append(turns);
		return hash.toHashCode();
	}

	/**
	 * Returns true if this is equal to the given object.
	 * @param object the object to compare.
	 * @return true if this is equal to the given object.
	 */
	@Override
	public boolean equals(Object object) {
		if (object == this) {
			return true;
		}
		if (object instanceof ExecuteTurns) {
			ExecuteTurns compare = (ExecuteTurns) object;
			EqualsBuilder equals = new EqualsBuilder();
			equals.append(this.loginId, compare.loginId);
			equals.append(this.instanceId, compare.instanceId);
			equals.append(this.turns, compare.turns);
			return equals.isEquals();
		}
		return false;
	}

	/**
	 * Compare this to the given object.
	 * @param compare the object to compare to.
	 * @return the result of the comparison.
	 */
	@Override
	public int compareTo(IExecuteTurns compare) {
		CompareToBuilder builder = new CompareToBuilder();
		builder.append(this.loginId, compare.getLoginId());
		builder.append(this.instanceId, compare.getInstanceId());
		builder.append(this.turns, compare.getTurns());
		return builder.toComparison();
	}

	/**
	 * Returns this as a string.
	 * @return this as a string.
	 */
	@Override
	public String toString() {
		ToStringBuilder string = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
		string.append("loginId", loginId);
		string.append("instanceId", instanceId);
		string.append("turns", turns);
		return string.toString();
	}

	public short getCommandId() {
		return COMMAND_ID;
	}
}
